package cjh;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;


import screen.LoginMain;


// 로그인 다이얼로그
public class LoginDialog extends JDialog {

	private JTextField id;
	private JPasswordField pw;
	static LoginMain log;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			LoginDialog dialog = new LoginDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public LoginDialog() {
		
		setLayout( new BorderLayout(0, 0) );
		setBounds(100, 100, 450, 450);
		makeTopPanel();
		makeCenterPanel();
		makeBotPanel();
			
				
				
	}		
	
			private void makeCenterPanel() {
			// 센터 패널 생성
			JPanel centerPanel = new JPanel();
			add(centerPanel, BorderLayout.CENTER);
			GridBagLayout gbl_center = new GridBagLayout();
			
			// 로그인 메세지 상하좌우 간격
			gbl_center.columnWidths = new int[]{0, 0, 0, 120, 0};
			gbl_center.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0};
			gbl_center.rowHeights = new int[]{10, 0, 20, 5, 2, 0};
			gbl_center.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
			centerPanel.setLayout(gbl_center);
			
			// 아이디 라벨 생성
			JLabel idl = new JLabel("아이디");
			idl.setFont(new Font("돋움", Font.BOLD, 16));
			GridBagConstraints gbc_idl = new GridBagConstraints();
			gbc_idl.anchor = GridBagConstraints.WEST;
			gbc_idl.gridx = 1;
			gbc_idl.gridy = 2;
			centerPanel.add(idl, gbc_idl);
	
			// 비밀번호 라벨
			JLabel pwl = new JLabel("비밀번호");
			pwl.setFont(new Font("돋움", Font.BOLD, 16));
			GridBagConstraints gbc_pwl = new GridBagConstraints();
			gbc_pwl.insets = new Insets(0, 0, 5, 5);
			gbc_pwl.gridx = 1;
			gbc_pwl.gridy = 3;
			centerPanel.add(pwl, gbc_pwl);
			
			
			
			// 아이디 및 비밀번호 생성
			{
				id = new JTextField();
				GridBagConstraints gbc_id = new GridBagConstraints();
				
				
					
			// 왼쪽 정렬
			gbc_id.fill = GridBagConstraints.HORIZONTAL;
			gbc_id.insets = new Insets(0, 0, 5, 5);
			gbc_id.gridx = 3;
			gbc_id.gridy = 2;
			centerPanel.add(id, gbc_id);
			
			// 비밀번호 입력 텍스트필드
			pw = new JPasswordField();
			GridBagConstraints gbc_pw = new GridBagConstraints();
			gbc_pw.insets = new Insets(0, 0, 5, 5);
			gbc_pw.fill = GridBagConstraints.HORIZONTAL;
			gbc_pw.gridx = 3;
			gbc_pw.gridy = 3;
				centerPanel.add(pw, gbc_pw);

			}
			
		}



		private void makeTopPanel() {
			// 상단패널 생성
			JPanel topPanel = new JPanel();
				
			JLabel login = new JLabel("Make set Image");					// 로그인 레이블 생성
			login.setFont(new Font("돋움", Font.BOLD, 18));
						
			topPanel.add(login);
					
			
			
			add(topPanel, BorderLayout.NORTH);
			
		}
		
		
			
		
		private void makeBotPanel() {

			JPanel botPanel = new JPanel();
			
			JButton okb = new JButton("로그인");
			okb.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int result = JOptionPane.showConfirmDialog(null, "로그인하시겠습니까", "로그인창입니다", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
					if( result == JOptionPane.YES_OPTION){
						setVisible(false);
						String id_VO = id.getText();
						String pwd_VO = pw.getText();
						System.out.println( pwd_VO );
						
					//  트루값
					if (  log.loginScreen(id_VO, pwd_VO ) ){
							setVisible( false );
							new AdminPage_Main( );
							dispose();
					
					}
					 
						
						// if ( id == )
						// setVO();// 체크를 한다음 체크값 반환
						// 페이지 넘어가기혹은 신 페이지 호출
											
						
																	
					}
					else if( result == JOptionPane.NO_OPTION)
						// 틀리다면 종료
						System.exit(0);
								
				}
			});
			
			
			botPanel.add(okb);
			
			JButton exit = new JButton( "나가기" );
			botPanel.add(exit);
			
			
			add(botPanel, BorderLayout.SOUTH);
			
		} // makeBotPanel
		
	}// LoginDialog


